//
//  OrderDetailTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/3.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class OrderDetailTableViewCell: UITableViewCell {
    @IBOutlet weak var shopName: UILabel!
    @IBOutlet weak var account: UILabel!
    @IBOutlet weak var persion: UILabel!
    @IBOutlet weak var address: UILabel!
    @IBOutlet weak var payType: UILabel!
    @IBOutlet weak var orderTime: UILabel!
    @IBOutlet weak var deliveryTime: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }
    
    func reload(withModel model:OrderListModel){
        self.shopName.text = "下单门店：" + (Utils.getUserDefaulsFor(key: "storeName") as! String)
        self.account.text = "下单账号：" + (Utils.getUserDefaulsFor(key: "username") as! String)
        var phone = ""
        if UserDefaults.standard.object(forKey: "phone") == nil {
            phone = UserDefaults.standard.object(forKey: "userPhone") as! String
        }else{
            phone = (Utils.getUserDefaulsFor(key: "phone") as! String)
        }
        self.persion.text = (Utils.getUserDefaulsFor(key: "name") as! String) + "  " + phone
        self.address.text = "收货地址：" + (Utils.getUserDefaulsFor(key: "address") as! String)
        
        // type 订单类型 0立即支付 1货到付款
        var text = ""
        
        if model.type == 1 {
            text = "支付方式：货到付款"
            // state 0 待支付 1 待发货  2 待收货  3  已完成 4 已取消  5 已退款
            if model.state == 0 {
                text = "支付方式：待支付"
            }
        }else {
            // 订单类型 0支付宝 1 微信 2 余额支付
            switch model.payType {
            case 0:
                if model.state == 0 {
                    text = "支付方式：待支付"
                }else{
                    text = "支付方式：支付宝支付"
                }
            case 1:
                text = "支付方式：微信支付"
            case 2:
                text = "支付方式：余额支付"
            default:
                break
            }
        }
        
        self.payType.text = text
        self.orderTime.text = "下单时间：" + ("\(model.createTime)".timeStampToString(timeFormat: "YYYY-MM-dd HH:mm:ss"))
        self.deliveryTime.text = model.serviceTime
    }

}
